package com.iti.jets.gpts.home;

// default package
// Generated Mar 22, 2014 9:41:00 PM by Hibernate Tools 3.4.0.CR1

import com.iti.jets.gpts.dao.AbstractDAO;
import com.iti.jets.gpts.pojo.TranServiceType;
import com.iti.jets.gpts.pojo.TranServiceTypeAttribute;
import com.iti.jets.gpts.pojo.TranServiceTypeAttributeType;
import java.io.Serializable;
import java.util.List;
import javax.naming.InitialContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.Restrictions;

/**
 * Home object for domain model class TranServiceTypeAttributeType.
 *
 * @see .TranServiceTypeAttributeType
 * @author Hibernate Tools
 */
public class TranServiceTypeAttributeTypeHome extends AbstractDAO<TranServiceTypeAttributeType> {

    public TranServiceTypeAttributeTypeHome(SessionFactory sessionFactory) {
        super(sessionFactory);
    }
private static final Log log = LogFactory.getLog(TerminalHome.class);
    private final SessionFactory sessionFactory = getSessionFactory();

    
    protected SessionFactory getSessionFactory() {
        try {
            return (SessionFactory) new InitialContext()
                    .lookup("SessionFactory");
        } catch (Exception e) {
            log.error("Could not locate SessionFactory in JNDI", e);
            throw new IllegalStateException(
                    "Could not locate SessionFactory in JNDI");
        }
    }

   public void persist(TranServiceTypeAttributeType tranServiceTypeAttributeTypeInstance) {
        log.debug("persisting TranServiceTypeAttributeType instance");
        try {
            sessionFactory.getCurrentSession().persist(tranServiceTypeAttributeTypeInstance);
            log.debug("persist successful");
        } catch (RuntimeException re) {
            log.error("persist failed", re);
            throw re;
        }
    }

    public void attachDirty(TranServiceTypeAttributeType instance) {
        log.debug("attaching dirty TranServiceTypeAttributeType instance");
        try {
            sessionFactory.getCurrentSession().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }

    public void attachClean(TranServiceTypeAttributeType instance) {
        log.debug("attaching clean TranServiceTypeAttributeType instance");
        try {
            sessionFactory.getCurrentSession().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }

    public void delete(TranServiceTypeAttributeType persistentInstance) {
        log.debug("deleting TranServiceTypeAttributeType instance");
        try {
            sessionFactory.getCurrentSession().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }

    public TranServiceTypeAttributeType merge(TranServiceTypeAttributeType detachedInstance) {
        log.debug("merging TranServiceTypeAttributeType instance");
        try {
            TranServiceTypeAttributeType result = (TranServiceTypeAttributeType) sessionFactory.getCurrentSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public TranServiceTypeAttributeType findById(int id) {
        log.debug("getting TranServiceTypeAttributeType instance with id: " + id);
        try {
            TranServiceTypeAttributeType instance = (TranServiceTypeAttributeType) sessionFactory.getCurrentSession()
                    .get("TranServiceTypeAttributeType", id);
            if (instance == null) {
                log.debug("get successful, no instance found");
            } else {
                log.debug("get successful, instance found");
            }
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }

    public List findByExample(TranServiceTypeAttributeType instance) {
        log.debug("finding TranServiceTypeAttributeType instance by example");
        try {
            List results = sessionFactory.getCurrentSession()
                    .createCriteria("TranServiceTypeAttributeType").add(Example.create(instance))
                    .list();
            log.debug("find by example successful, result size: "
                    + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }
}
